package zerous.craft;

import android.content.*;
import android.graphics.*;
import java.io.*;
import android.content.res.*;

public class Utils
{
	public static boolean hitLeft,hitTop,hitButton;
	public static Bitmap getBitmapFromAssets(Context context,String file)
	{
		Bitmap bitmap;
		try{
			AssetManager assets = context.getResources().getAssets();
			InputStream in = assets.open(file);
			bitmap = BitmapFactory.decodeStream(in);
			in.close();
			return bitmap;
		}
		catch(IOException e)
		{
			return null;
		}
	}
	
	public static Bitmap flip(Bitmap b,boolean ToR)
	{
		Bitmap bitmap;
		Matrix m = new Matrix();
		if(ToR == true)
		{
			m.postScale(-1,1);
			bitmap = Bitmap.createBitmap(b,0,0,b.getWidth(),b.getHeight(),m,true);
			return bitmap;
		}
		else
		{
			m.postScale(1,-1);
			bitmap = bitmap.createBitmap(b,0,0,b.getWidth(),b.getHeight(),m,true);
			return bitmap;
		}
	}
	
	public static Bitmap scale(Bitmap bitmap, float scaleX, float scaleY)
	{
		Matrix matrix = new Matrix(); 
		matrix.postScale(scaleX,scaleY);
		Bitmap resizeBmp = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,false);
		return resizeBmp;
	} 
	
}
